(function($){
	$.fn.imgIframeUpload = function(settings) {
		
		var form;
		var iframe; 
		var	self = this;
		var	selfId = self.attr('id'); 
		var	opts = {
			action: "iframe_upload.php",
			callback: null
		};
		$.extend(opts, settings);
		
		form = $('<form method="post" action="' + opts.action + '" enctype="multipart/form-data" target="iframe-upload-' + selfId + '" style="display:none;"><input type="hidden" name="old_temp" /><input type="hidden" name="callback_script" value="' + (opts.callback ? ('parent.' + opts.callback + '($res);') : '') + '" /></form>');
		iframe = $('<iframe name="iframe-upload-' + selfId + '" frameborder="0" style="display:none;" src="about:blank"></iframe>');
		$('body').append(form).append(iframe);

		function fileChange(obj){
			obj.change(function(){
				var fileInputClone = $(this).clone().val('').hide();
				$(this).after(fileInputClone).attr('name', 'temp[]').removeAttr('id').appendTo(form);
				fileInputClone.css('display', 'inline');
				fileChange(fileInputClone);
				form.submit();
				$(this).remove();
			});
		}

		fileChange(self);

	}
})(jQuery);